       
//图片预加载
var databool = true;
var call = false;
function getImg (src,smallw,type,fn,imgobj){
    call = false;
    var imgs = new Image();
    imgs.src = src;
    if(imgs.complete){
        fn(imgs.width,imgs.height,smallw,imgobj,type);
    }else{
        imgs.onload = function(){ 
            fn(imgs.width,imgs.height,smallw,imgobj,type);
        }
    }

}
function callback(w,h,smallw,img,type){
    call = true;
    switch(type){
        case 1:
            var n =smallw/w;
            h = Math.floor(h*n);
            img.css('width',smallw);
            img.css('height',h);
            break;
        case 2:
            var n = smallw/w;
            var m = smallw/h;
            if(n<=m){
                img.css('width',smallw);
                img.css('height',Math.floor(h*n));
            }else{
                img.css('width',Math.floor(w*m));
                img.css('height',smallw);
            }
            break;
        case 3:
            if(w<=smallw){
                img.css({
                    width:w,
                    height:h
                });  
            }else{
                var n = smallw/w;
                h = Math.floor(h*n);
                img.css('width',smallw);
                img.css('height',h);
            }
    }
}
//获得滚动时最后一个div
function getLast(obj){
    var windowH = document.body.clientHeight || document.documentElement.clientHeight;
    var scrollH = $(window).scrollTop();
    obj = obj.eq(obj.length-1);
    var objH = obj.outerHeight(true)/2+obj.offset().top;
    return objH<(windowH+scrollH)?true:false;   
}
water.boxTop=[];
water.json = [];
function water(obj,num,a){
    if(a<=5){
        obj.each(function(index,box){
            if(index<num){
                water.boxTop.push($(box).outerHeight(true));
            }
        })
    }
    for(var i=a;i<obj.length;i++){
        var minHeight = Math.min.apply(false,water.boxTop);
        if(i>=a&&i<=10){
            obj.eq(i).css('position','absolute');
        }
        var minLeftindex =getMinHeight(water.boxTop,minHeight);
        if(i>10){
            obj.eq(i).animate({
                top:minHeight,
                left:obj.eq(minLeftindex).position().left
            },500)
        }else{
            obj.eq(i).css({
                top:minHeight,
                left:obj.eq(minLeftindex).position().left
            })
        }
        water.json.push([minLeftindex,i])
        water.boxTop[minLeftindex] = obj.eq(i).outerHeight()+ water.boxTop[minLeftindex];
    }     
    function getMinHeight(arr,min){
        var index = '';
        for( var i in arr){
            if(arr[i] == min){
                index = i;
            }
        }
        return index;
    }            
}
//设置瀑布流对象的属性
function setObj(obj){
    obj.css({
        'position':'absolute',
        top:$(window).height()+$(window).scrollTop(),
        left:(($(window).width())-200)/2
    })
}
